﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Base.Util.Reader;
namespace AAA.Command.WCF
{
	public class ReturnCodeManager
	{
		private Dictionary<int, string> _dicReturnCodes = new Dictionary<int, string>();

		public void Add(IniReader iniReader)
		{
			foreach (string strReturnCode in iniReader.GetKey("Default"))
				Add(strReturnCode, iniReader.GetParam(strReturnCode));
		}

		public void Add(string strReturnCode, string strMessage)
		{
			try { Add(Int32.Parse(strReturnCode), strMessage); }
			catch { }		
		}

		public void Add(string strReturnCode, string strMessage, bool isOverWrite)
		{
			try { Add(Int32.Parse(strReturnCode), strMessage, isOverWrite); }
			catch { }
		}

		public void Add(int iReturnCode, string strMessage)
		{
			Add(iReturnCode, strMessage, true);
		}

		public void Add(int iReturnCode, string strMessage, bool isOverWrite)
		{
			if (!_dicReturnCodes.ContainsKey(iReturnCode))
				_dicReturnCodes.Add(iReturnCode, strMessage);
			else if (isOverWrite)
				_dicReturnCodes[iReturnCode] = strMessage;
		}

		public string GetMessage(string strReturnCode)
		{
			try { return GetMessage(Int32.Parse(strReturnCode));}
			catch { return "";}
		}

		public string GetMessage(int intReturnCode)
		{
			return _dicReturnCodes.ContainsKey(intReturnCode) 
				? _dicReturnCodes[intReturnCode] 
				: "";
		}
	}
}
